﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Get Point</title>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=1jH6jjDl5M5zg66FQilXglBkh2havWPH"></script>
</head>
<body>
<div id="map" style="width:1080px;height:1024px"></div>
<script type="text/javascript">
  var map = new BMap.Map('map',{enableMapClick:false});
  map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
  map.addEventListener('rightclick', function (e) {
    window.external.SetCenter(e.point.lng, e.point.lat);
  });
  // 添加带有定位的导航控件
  var navigationControl = new BMap.NavigationControl({
    // 靠左上角位置
    anchor: BMAP_ANCHOR_TOP_LEFT,
    // LARGE类型
    type: BMAP_NAVIGATION_CONTROL_LARGE,
    // 启用显示定位
    enableGeolocation: true
  });
  map.addControl(navigationControl);
  
  map.enableScrollWheelZoom();
  map.enableInertialDragging();
  map.enableContinuousZoom();
  var size = new BMap.Size(100, 10);
  map.addControl(new BMap.CityListControl({
    anchor: BMAP_ANCHOR_TOP_LEFT,
    offset: size   
   }));

  function resize(width,height){
      var mapDiv = document.getElementById('map');
	  mapDiv.style.width=width;
	  mapDiv.style.height=height;
  }
  function setPoint(lng,lat){
    var point = new BMap.Point(lng,lat);
	map.panTo(point);	
	map.clearOverlays(); 
	var marker = new BMap.Marker(point);  // 创建标注
	map.addOverlay(marker);              // 将标注添加到地图中
  }
  function search(keyword){
    var local = new BMap.LocalSearch(map, {
		renderOptions:{map: map}
	});	
	local.search(keyword);
  }
  function getMapBounds(){
    var bs = map.getBounds();   //获取可视区域
	var bssw = bs.getSouthWest();   //可视区域左下角
	var bsne = bs.getNorthEast();   //可视区域右上角
	window.external.getMapBounds( bsne.lng, bsne.lat, bssw.lng, bssw.lat);	
	//alert("当前地图可视范围是：" + bssw.lng + "," + bssw.lat + "到" + bsne.lng + "," + bsne.lat);
  }
   function setMapBounds( neLng,neLat,swLng,swLat){
    var b = new BMap.Bounds(new BMap.Point(neLng, neLat),new BMap.Point(swLng,swLat));
	try {	
		BMapLib.AreaRestriction.setBounds(map, b);
	} catch (e) {
		alert(e);
	}
  }
</script>
</body>
</html>
